//
//  ALTabBarVC.m
//  FanBei
//
//  Created by 哀木涕 on 2016/12/27.
//  Copyright © 2016年 chuxiangkeji. All rights reserved.
//

#import "ALTabBarVC.h"

@interface ALTabBarVC ()<UITabBarControllerDelegate>

@end

@implementation ALTabBarVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    UIStoryboard *home = [UIStoryboard storyboardWithName:SB_home bundle:nil];
    UIStoryboard *rebate = [UIStoryboard storyboardWithName:SB_rebate bundle:nil];
    UIStoryboard *search = [UIStoryboard storyboardWithName:SB_search bundle:nil];
    UIStoryboard *stages = [UIStoryboard storyboardWithName:SB_Stages bundle:nil];
    UIStoryboard *mine = [UIStoryboard storyboardWithName:SB_mine bundle:nil];
    
    
    UIViewController *homeRootVC   = home.instantiateInitialViewController;
    UIViewController *rebateRootVC = rebate.instantiateInitialViewController;
    UIViewController *searchRootVC = search.instantiateInitialViewController;
    UIViewController *stagesRootVC = stages.instantiateInitialViewController;
    UIViewController *mineRootVC   = mine.instantiateInitialViewController;

    
    self.viewControllers = @[homeRootVC,rebateRootVC,searchRootVC,stagesRootVC,mineRootVC];
    
    [self createTabBarItemWithTitle:@"首页" withUnSelectedImage:@"home-0" withSelectedImage:@"home-1" withTag:0];
    [self createTabBarItemWithTitle:@"返呗" withUnSelectedImage:@"list-0" withSelectedImage:@"list-1" withTag:1];
    [self createTabBarItemWithTitle:@"搜呗" withUnSelectedImage:@"more-0" withSelectedImage:@"more-1" withTag:2];
    [self createTabBarItemWithTitle:@"分呗" withUnSelectedImage:@"my-0" withSelectedImage:@"my-1" withTag:3];
    [self createTabBarItemWithTitle:@"我的" withUnSelectedImage:@"my-0" withSelectedImage:@"my-1" withTag:4];
}
-(void)createTabBarItemWithTitle:(NSString *)title withUnSelectedImage:(NSString *)unSelectedImage withSelectedImage:(NSString *)selectedImage withTag:(int)tag
{
    UIImage *image1_0 = [[UIImage imageNamed:unSelectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage *image1_1 = [[[UIImage imageNamed:selectedImage] imageWithTintColor:MainColor] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    (void)[[self.tabBar.items objectAtIndex:tag] initWithTitle:title image:image1_0 selectedImage:image1_1];
    
    [[self.tabBar.items objectAtIndex:tag] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:MainColor, NSForegroundColorAttributeName,nil] forState:UIControlStateSelected];
    
}


#pragma mark tabBarControllerdelegate
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
    NSInteger index = [tabBarController.viewControllers indexOfObject:viewController];
    if (index == 3 || index == 4) {
        if (![ALSingleTon shareSingTon].isLogin) {
            // TODO --- 模态登录界面
            return NO;
        }
        
    }
    return YES;
}
@end
